package com.beifeng.secondsort;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.WritableComparable;

public class SecondKey  implements WritableComparable<SecondKey>{
	private int year;
	private double temp;
	private String date;
	
	public SecondKey(){
	}
	

	
	public int getYear() {
		return year;
	}



	public void setYear(int year) {
		this.year = year;
	}



	public double getTemp() {
		return temp;
	}



	public void setTemp(double temp) {
		this.temp = temp;
	}



	public String getDate() {
		return date;
	}



	public void setDate(String date) {
		this.date = date;
	}
	
	public void setAll(int year,double temp,String date) {
		this.year = year;
		this.temp = temp;
		this.date = date;
	}


	public SecondKey(int year, double temp, String date) {
		this.year = year;
		this.temp = temp;
		this.date = date;
	}



	public void write(DataOutput out) throws IOException {
		// TODO Auto-generated method stub
		out.writeInt(year);
		out.writeDouble(temp);
		out.writeUTF(date);
		
	}

	public void readFields(DataInput in) throws IOException {
		// TODO Auto-generated method stub
		this.year = in.readInt();
		this.temp = in.readDouble();
		this.date = in.readUTF();
	}

	public int compareTo(SecondKey o) {
		// TODO Auto-generated method stub
		System.out.println("-----进行排序------");
		if(this.year==o.year){
			return this.temp-o.temp>0?1:-1;
		}
		return this.year-o.year;
	}



	@Override
	public String toString() {
		return "年份=" + year + " \t温度=" + temp + " \t日期=" + date;
	}
	
	
	
}
